import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.CharArrayReader;
import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;

public class MemoryStreams {

  public static void main(String[] args) throws IOException {
    String text = "Kiril\nMaria\nIvan\n";
    CharArrayReader reader = new CharArrayReader(text.toCharArray());
    // StringReader reader = new StringReader(text);
    BufferedReader buffReader = new BufferedReader(reader);
    CharArrayWriter writer = new CharArrayWriter();
    //StringWriter writer =  new StringWriter();
    BufferedWriter bw = new BufferedWriter(writer);
    String line = null;
    try {
      while ((line = buffReader.readLine()) != null) {
        bw.write(line);
      }
    } catch (IOException e) {
      System.err.println("Error while reading from source.");
    } finally {
      buffReader.close();
      // do we need that?
      reader.close();
      bw.close();
    }
    System.out.println(writer.toString());
  }

}
